/*
Project: 		The Impact of Short-Term Employment for Low-Income Youth: Experimental 	
				Evidence from the Philippines
Authors: 		Emily A. Beam and Stella Quimbo

***********************************
Path: 			code/02_analysis
File name: 		table_b09_b10_b11.do 
***********************************

Purpose: 		Generates Tables 7 and associated appendix tables for perceptions/aspirations

Inputs: 		spes_data.dta
Outputs: 			*Table B9 = table3_ivspes_panel_nocov.tex
					*Table B10 = table5_ivspes_panel_nocov.tex
					*Table B11 = table6_ivspes_panel_nocov.tex

Log: 			results/03_output/log_table_b09_b10_b11.log		

Last updated: 	18 November 2021

*/


cap log close 
log using "$output/log_table_b09_b10_b11.log",replace 

estimates clear
use "$usedata_analysis/spes_data",clear 
	keep if endline == 1



*** Set up local variables 

local l_bb_female "Female"
local l_NT_edu "College"

local intlist "_bb_female _NT_edu"

local n: word count $cov1
	assert `n' == 18 

** Interaction terms 

foreach interact in  `intlist' {
	
	foreach mes in tr spes_2016{
gen `mes'X`interact' = `mes'*`interact'
label var `mes'X`interact' "SPES X `l`interact''"

	}

assert !missing(`interact')

gen `interact'xtreatment = `interact'*treatment
label var `interact'xtreatment "SPES X `l`interact''"


* Generate inteaction terms for each covariate 

ds $cov1 
foreach cov in `r(varlist)'{ 
gen `interact'X`cov' = `cov'*`interact'
} 

}




* Set locals 
local depvar1 	_eeo_worknow 		_eeo_jobsearch 			_eeo_wage_mn 		_eeo_workhours  			
local labels1 "	"Currently working (formal)" 	"Looked for work since 2016" 		"Currently earning"  			"Work hours weekly now" "
					

local depvar2 	_eeo_emped 		_eeo_noemped 			_eeo_empnoed 		_eeo_noempnoed  			
local labels2 "	"Enrolled and working" 	"Enrolled, not working" 		"Not enrolled, working"  			"Not enrolled, not working" "
							
local depvar3 _eeo_enroll  _eeo_enr_ny _eeo_gwan _eeo_at
local labels3 " "Currently Enrolled"  "Enroll next year"  "Normalized GWA" " Academic Track""



										
loc w = 1				
local name1 "employment" 
local name2 "employment-ed"
local name3 "educ"

forval j = 1/3{		
					

local r replace



** Uninteracted version ** 
	foreach var in `depvar`j'' {
	
foreach mes in  spes_2016{

		qui xi:  ivregress 2sls  `var' (`mes' = treatment )  i.scel if treatment!=. ,  robust
		estimates store iv`mes'`var'
		summ `var' if treatment==0 
		estadd scalar dmean = `r(mean)'


}
	
	}
	

	foreach var in `depvar`j'' {


foreach interact in `intlist'  {


		
		
foreach mes in  spes_2016{

	
	qui	xi:  ivregress 2sls  `var' (`mes' `mes'X`interact' = treatment `interact'xtreatment) i.scel if treatment!=. & _f`interact' == 0,  robust
		
		estimates store iv`mes'`w'`interact'
		di in red "estimates stored as iv`mes'`w'`interact'"
		summ `var' if treatment==0 
		estadd scalar dmean = `r(mean)'
		
		test `mes' + `mes'X`interact' == 0 
		local pval = `r(p)'
		estadd scalar pvalint = `r(p)'
}	// nature of IV loop
		

	
	}		// interaction term
	
	local w = `w' + 1
}		// individual dependent variables within each set
	
}		// dependent variable sets (tables)	

		


********************************************
********************************************



** Table numbers 

loc tnemp 		= 3		// employment 
loc tneduc 		= 5		// education 
loc tneduemp 	= 6		// education and employment

*** Footnote text 



local fn`tneduemp' = "\multicolumn{5}{p{\textwidth}}{\footnotesize{Notes: All endline respondents included. All specifications include stratification-cell fixed effects only. \textit{*** p$<$0.01, ** p$<$0.05, * p$<$0.10} }}\\"

local fn`tnemp' = "\multicolumn{5}{p{\textwidth}}{\footnotesize{Notes: All endline respondents included. All specifications include stratification-cell fixed effects only. \textit{*** p$<$0.01, ** p$<$0.05, * p$<$0.10} }}\\"

local fn`tneduc' = "\multicolumn{5}{p{\textwidth}}{\footnotesize{Notes: All endline respondents included, column 4 restricted to students enrolled in grade 11 and 12.  Grade-weighted average normalized using education-level and scale-specific means and standard deviations of the control group. All specifications include stratification-cell fixed effects only. \textit{*** p$<$0.01, ** p$<$0.05, * p$<$0.10} }}\\"


********************************************
********************************************
cd "$tables_analysis"
#delimit ; 
********** Table 3 - employment  *************;
{;
	
	
	
	// Output Tables ;

foreach mes in  spes_2016{;
	
	esttab iv`mes'_eeo_worknow 		iv`mes'_eeo_jobsearch 			iv`mes'_eeo_wage_mn 		iv`mes'_eeo_workhours  	
	using table`tnemp'_iv_`mes'.tex, replace star(* 0.10 ** 0.05 *** 0.01) 
	cells("b(fmt(3) star)" "se(par([ ]))") 
	stats() noobs
	keep(`mes') label  
	varwidth(16) modelwidth(13) style(tex) 
	title(Impact of SPES on employment\label{temployment}) 
	varlabels(_cons Constant) 
	mlabels("Currently working (formal)" "Looked for work" 
			"Current monthly earnings"  	"Work hours weekly now" , 
			span prefix(\multicolumn{@span}{x{0.15\textwidth}}{) suffix(})) 
	collabels(none)
	prehead( "\begin{tabular}{lcccc}" "\toprule") 
	posthead(\hline) 
	prefoot() 
	postfoot("\bottomrule");
};




	//* Panel B Female;
	
foreach mes in  spes_2016{;

	esttab iv`mes'1_bb_female 		iv`mes'2_bb_female		iv`mes'3_bb_female		iv`mes'4_bb_female  			  
	using table`tnemp'_iv_`mes'_bb_female.tex, replace star(* 0.10 ** 0.05 *** 0.01) 
	cells("b(fmt(3) star)" "se(par([ ]))") 
	stats( pvalint , fmt(%9.3f  )  
	labels(  "p-value, SPES + SPES X Female")) 
	keep(`mes' `mes'X_bb_female) label  
	varwidth(16) modelwidth(13) style(tex) 
	title(Impact of SPES on employment\label{temployment}) 
	varlabels(_cons Constant) 
	mlabels("Currently working (formal)" 	"Looked for work" 	
			"Current monthly earnings" 	"Work hours weekly now" , 
			span prefix(\multicolumn{@span}{x{0.15\textwidth}}{) suffix(})) 
	collabels(none)
	prehead("\begin{table}\caption{@title}" "\begin{center}"  "\begin{tabular}{lcccc}" "\toprule") 
	posthead(\hline) 
	prefoot() 
	postfoot("\bottomrule"  );
};
	//* Panel C Education ;

	
foreach mes in  spes_2016{;

	esttab iv`mes'1_NT_edu		iv`mes'2_NT_edu 			iv`mes'3_NT_edu		iv`mes'4_NT_edu  			  
	using table`tnemp'_iv_`mes'_NT_edu.tex, replace star(* 0.10 ** 0.05 *** 0.01) 
	cells("b(fmt(3) star)" "se(par([ ]))") 
	stats(pvalint N   dmean, fmt(%9.3f  %9.0f %9.3f )  
	labels( "p-value, SPES + SPES X College" "Observations"  "Mean, control group")) 
	keep(`mes' `mes'X_NT_edu) label  varwidth(16) modelwidth(13) style(tex) 
	title(Impact of SPES on employment\label{temployment}) 
	varlabels(_cons Constant) 
	mlabels("Currently working (formal)" 	"Looked for work" 	
			"Current monthly earnings"  			"Work hours weekly now" ,
			span prefix(\multicolumn{@span}{x{0.15\textwidth}}{) suffix(})) 
	collabels(none)
	prehead("\begin{table}\caption{@title}" "\begin{center}"  "\begin{tabular}{lcccc}" "\toprule") 
	posthead(\hline) prefoot() postfoot("\bottomrule" "`fn`tnemp''" "\end{tabular}" );
};






include "$dofiles/PanelCombine.do";



// Table 3  - IV - self report ;
panelcombine, use(table`tnemp'_iv_spes_2016.tex table`tnemp'_iv_spes_2016_bb_female.tex table`tnemp'_iv_spes_2016_NT_edu.tex)  
columncount(5)  paneltitles("Aggregate treatment effects" "Interacted by gender" "Interacted by education level") 
save(table`tnemp'_ivspes_panel_nocov.tex) cleanup;





};

********** Table 5 - education  *************;
{;
	

	#delimit ; 
	// Output Tables ;

	
foreach mes in  spes_2016{;
	
	esttab iv`mes'_eeo_enroll 		iv`mes'_eeo_enr_ny 		iv`mes'_eeo_gwan		iv`mes'_eeo_at	
	using table`tneduc'_iv_`mes'.tex, replace star(* 0.10 ** 0.05 *** 0.01) 
	cells("b(fmt(3) star)" "se(par([ ]))") 
	keep(`mes') label  noobs
	varwidth(16) modelwidth(13) style(tex) 
	title(Impact of SPES on education\label{teduc}) 
	varlabels(_cons Constant) 
	mlabels("Enrolled in school" "Will enroll, 2017-18" "Grade-Weighted Average" "Academic track, SHS only",
			span prefix(\multicolumn{@span}{x{0.15\textwidth}}{) suffix(})) 
	collabels(none)
	prehead( "\begin{tabular}{lcccc}" "\toprule") 
	posthead(\hline) 
	prefoot() 
	postfoot("\bottomrule");
};


	//* Panel B Female;
	
	
foreach mes in  spes_2016{;

	esttab iv`mes'9_bb_female 		iv`mes'10_bb_female		iv`mes'11_bb_female		iv`mes'12_bb_female  			  
	using table`tneduc'_iv_`mes'_bb_female.tex, replace star(* 0.10 ** 0.05 *** 0.01) 
	cells("b(fmt(3) star)" "se(par([ ]))") 
	stats( pvalint, fmt(%9.3f  )  
	labels(  "p-value, SPES + SPES X Female" )) 
	keep(`mes' `mes'X_bb_female) label  
	varwidth(16) modelwidth(13) style(tex) 
	title(Impact of SPES on education\label{teduc}) 
	varlabels(_cons Constant) 
	mlabels("Enrolled in school" "Will enroll, 2017-18" "Grade-Weighted Average" "Academic track, SHS only",
			span prefix(\multicolumn{@span}{x{0.15\textwidth}}{) suffix(})) 
	collabels(none)
	prehead("\begin{table}\caption{@title}" "\begin{center}"  "\begin{tabular}{lcccc}" "\toprule") 
	posthead(\hline) 
	prefoot() 
	postfoot("\bottomrule"  );
};
	//* Panel C Education ;
	
	
foreach mes in  spes_2016{;

	esttab iv`mes'9_NT_edu		iv`mes'10_NT_edu 			iv`mes'11_NT_edu		  			  
	using table`tneduc'_iv_`mes'_NT_edu.tex, replace star(* 0.10 ** 0.05 *** 0.01) 
	cells("b(fmt(3) star)" "se(par([ ]))") 
	stats(pvalint N dmean , fmt(%9.3f %9.0f %9.3f )  
	labels("p-value, SPES + SPES X College" "Observations" "Mean, control group" )) 
	keep(`mes' `mes'X_NT_edu) label  varwidth(16) modelwidth(13) style(tex) 
	title(Impact of SPES on education\label{teduc}) 
	varlabels(_cons Constant) 
	mlabels("Enrolled in school" "Will enroll, 2017-18" "Grade-Weighted Average" "Academic track, SHS only",
			span prefix(\multicolumn{@span}{x{0.15\textwidth}}{) suffix(})) 
	collabels(none)
	prehead("\begin{table}\caption{@title}" "\begin{center}"  "\begin{tabular}{lcccc}" "\toprule") 
	posthead(\hline) prefoot() postfoot("\bottomrule" "`fn`tneduc''" "\end{tabular}" );
};






// Table 5  - IV - self report ;
panelcombine, use(table`tneduc'_iv_spes_2016.tex table`tneduc'_iv_spes_2016_bb_female.tex table`tneduc'_iv_spes_2016_NT_edu.tex)  
columncount(5)  paneltitles("Aggregate treatment effects" "Interacted by gender" "Interacted by education level") 
save(table`tneduc'_ivspes_panel_nocov.tex) cleanup;


};

********** Table 6 - education/ed *************;
{;
	// Output Tables ;




	
foreach mes in  spes_2016{;
	
	esttab iv`mes'_eeo_emped 		iv`mes'_eeo_noemped			iv`mes'_eeo_empnoed 		iv`mes'_eeo_noempnoed
	using table`tneduemp'_iv_`mes'.tex, replace star(* 0.10 ** 0.05 *** 0.01) 
	cells("b(fmt(3) star)" "se(par([ ]))") noobs 
	keep(`mes') label  varwidth(16) modelwidth(13) style(tex) 
	title(Impact of SPES on employment\label{temployment}) 
	varlabels(_cons Constant) 
	mlabels("Enrolled and working" 	"Enrolled, not working" 	
			"Not enrolled, working"  			"Not enrolled, not working" , 
			span prefix(\multicolumn{@span}{x{0.15\textwidth}}{) suffix(})) 
	collabels(none) 
	prehead( "\begin{tabular}{lcccc}" "\toprule") posthead(\hline) prefoot() postfoot("\bottomrule");
};




	//* Panel B Female;
	
	
foreach mes in  spes_2016{;

	esttab iv`mes'5_bb_female 		iv`mes'6_bb_female		iv`mes'7_bb_female		iv`mes'8_bb_female  			  using 
	table`tneduemp'_iv_`mes'_bb_female.tex, replace star(* 0.10 ** 0.05 *** 0.01) 
	cells("b(fmt(3) star)" "se(par([ ]))") 
	stats( pvalint , fmt(%9.3f  )  
	labels(  "p-value, SPES + SPES X Female")) 
	keep(`mes' `mes'X_bb_female) label  varwidth(16) modelwidth(13) style(tex) 
	title(Impact of SPES on employment\label{temployment}) 
	varlabels(_cons Constant) 
	mlabels("Enrolled and working" 				"Enrolled, not working" 		
			"Not enrolled, working"  			"Not enrolled, not working", 
			span prefix(\multicolumn{@span}{x{0.15\textwidth}}{) suffix(})) 
	prehead("\begin{table}\caption{@title}" "\begin{center}"  "\begin{tabular}{lcccc}" "\toprule") 
	posthead(\hline) prefoot() postfoot("\bottomrule"  );
};
	//* Panel C Education ;
	
	
foreach mes in  spes_2016{;

	esttab iv`mes'5_NT_edu		iv`mes'6_NT_edu 			iv`mes'7_NT_edu		iv`mes'8_NT_edu  			  
	using table`tneduemp'_iv_`mes'_NT_edu.tex, replace star(* 0.10 ** 0.05 *** 0.01) 
	cells("b(fmt(3) star)" "se(par([ ]))") 
	stats(pvalint N dmean , fmt(%9.3f %9.0f %9.3f  )  
	labels( "p-value, SPES + SPES X College" "Observations" "Mean, control group" )) 
	keep(`mes' `mes'X_NT_edu) label  varwidth(16) modelwidth(13) style(tex) 
	title(Impact of SPES on employment\label{temployment}) varlabels(_cons Constant) 
	mlabels("Enrolled and working" 	"Enrolled, not working" 		
			"Not enrolled, working"  			"Not enrolled, not working" , 
			span prefix(\multicolumn{@span}{x{0.15\textwidth}}{) suffix(})) 
	prehead("\begin{table}\caption{@title}" "\begin{center}"  "\begin{tabular}{lcccc}" "\toprule") 
	posthead(\hline) prefoot() postfoot("\bottomrule" "`fn`tneduemp''" "\end{tabular}" );
};



// Table 6  - IV - self report ;
panelcombine, use(table`tneduemp'_iv_spes_2016.tex table`tneduemp'_iv_spes_2016_bb_female.tex table`tneduemp'_iv_spes_2016_NT_edu.tex)  columncount(5)  paneltitles("Aggregate treatment effects" "Interacted by gender" "Interacted by education level") cleanup
save(table`tneduemp'_ivspes_panel_nocov.tex) ;


};



log close;

exit;
